package jjn.carl.greedy;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/1 16:11
 */
public class LeetCode452 {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, (first, second) -> {
            if (first[0] == second[0]) {
                return Integer.compare(first[1], second[1]);
            }
            return Integer.compare(first[0], second[0]);
        });
        int count = 1;
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] > points[i - 1][1]) {
                count++;
            } else {
                points[i][1] = Math.min(points[i][1], points[i - 1][1]);
            }
        }
        return count;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[][] points = new int[count][2];
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 2; j++) {
                points[i][j] = scanner.nextInt();
            }
        }
        int minArrowShots = new LeetCode452().findMinArrowShots(points);
        System.out.println(minArrowShots);
    }
}
